package br.usp.ime.ingpos.testes.services;

import javax.servlet.http.HttpServletRequest;

import org.junit.Before;
import org.junit.Test;

import br.com.caelum.vraptor.util.test.MockLocalization;
import br.usp.ime.ingpos.modelo.dao.UsuarioDao;
import br.usp.ime.ingpos.services.EmailException;
import br.usp.ime.ingpos.services.EmailService;
import br.usp.ime.ingpos.services.SenhaService;
import br.usp.ime.ingpos.testes.BancoDeDadosTestCase;

public class SenhaServiceTest extends BancoDeDadosTestCase {
	private final HttpServletRequest httpServletRequest = null;
	private SenhaService senhaService;

	public SenhaServiceTest(String name) {
		super(name);
	}

	@Before
	protected void setUp() throws Exception {
		super.setUp();
		
		try {
			senhaService = new SenhaService(
					new UsuarioDao(getSessionCreator()), new EmailService(
							EmailServiceTeste.construirSessionParaTeste()),
					new MockLocalization(), httpServletRequest);
		} catch (EmailException e) {
			assertTrue(false);
			e.printStackTrace();
		}
	}

	@Test
	public void testEnviarEmailSucedido() {
		assertTrue(senhaService
				.enviarEmailSucedido(RegistroNovoUsuarioServiceTeste.EMAIL));
		assertFalse(senhaService
				.enviarEmailSucedido("zezao@ime.usp.br"));
	}

	@Test
	public void testAtualizaSenha() {
		String emailInvalido = "zezao@ime.usp.br";
		
		senhaService.atualizarSenha(RegistroNovoUsuarioServiceTeste.EMAIL, "123456");
		senhaService.atualizarSenha(emailInvalido, "123456");
	}
}
